package zsk;

import java.util.HashMap;
import java.util.Map;

public abstract class UTF8 {
	protected static HashMap<String, String> charmap;

	public static String changeHTMLtoUTF8(String stringtochange) {
		
		String ssource = stringtochange; // to avoid javac warning about parameter assignment
		UTF8.charmap = new HashMap<String, String>();
		
		// fill hasmap

		charmap.put("&#32;"," "); 
		charmap.put("&#160;"," ");
		charmap.put("&nbsp;"," ");
		charmap.put("&#33;","!"); 
		charmap.put("&#34;","\"");
		charmap.put("&quot;","\"");
		charmap.put("&#35;","#"); 
		charmap.put("&#36;","$"); 
		charmap.put("&#37;","%"); 
		charmap.put("&#38;","&"); 
		charmap.put("&#39;","'"); 
		charmap.put("&#40;","("); 
		charmap.put("&#41;",")"); 
		charmap.put("&#42;","*"); 
		charmap.put("&#43;","+"); 
		charmap.put("&#44;",","); 
		charmap.put("&#45;","-"); 
		charmap.put("&#46;","."); 
		charmap.put("&#47;","/"); 
		charmap.put("&#48;","0"); 
		charmap.put("&#49;","1"); 
		charmap.put("&#50;","2"); 
		charmap.put("&#51;","3"); 
		charmap.put("&#52;","4"); 
		charmap.put("&#53;","5"); 
		charmap.put("&#54;","6"); 
		charmap.put("&#55;","7"); 
		charmap.put("&#56;","8"); 
		charmap.put("&#57;","9"); 
		charmap.put("&#58;",":"); 
		charmap.put("&#59;",";"); 
		charmap.put("&#60;","<");
		charmap.put("&lt;","<");
		charmap.put("&#61;","="); 
		charmap.put("&#62;",">");
		charmap.put("&gt;",">");
		charmap.put("&#63;","?"); 
		charmap.put("&#64;","@"); 
		charmap.put("&#65;","A"); 
		charmap.put("&#66;","B"); 
		charmap.put("&#67;","C"); 
		charmap.put("&#68;","D"); 
		charmap.put("&#69;","E"); 
		charmap.put("&#70;","F"); 
		charmap.put("&#71;","G"); 
		charmap.put("&#72;","H"); 
		charmap.put("&#73;","I"); 
		charmap.put("&#74;","J"); 
		charmap.put("&#75;","K"); 
		charmap.put("&#76;","L"); 
		charmap.put("&#77;","M"); 
		charmap.put("&#78;","N"); 
		charmap.put("&#79;","O"); 
		charmap.put("&#80;","P"); 
		charmap.put("&#81;","Q"); 
		charmap.put("&#82;","R"); 
		charmap.put("&#83;","S"); 
		charmap.put("&#84;","T"); 
		charmap.put("&#85;","U"); 
		charmap.put("&#86;","V"); 
		charmap.put("&#87;","W"); 
		charmap.put("&#88;","X"); 
		charmap.put("&#89;","Y"); 
		charmap.put("&#90;","Z"); 
		charmap.put("&#91;","["); 
		charmap.put("&#92;","\\"); 
		charmap.put("&#93;","]"); 
		charmap.put("&#94;","^"); 
		charmap.put("&#95;","_"); 
		charmap.put("&#96;","`"); 
		charmap.put("&#97;","a"); 
		charmap.put("&#98;","b"); 
		charmap.put("&#99;","c"); 
		charmap.put("&#100;","d"); 
		charmap.put("&#101;","e"); 
		charmap.put("&#102;","f"); 
		charmap.put("&#103;","g"); 
		charmap.put("&#104;","h"); 
		charmap.put("&#105;","i"); 
		charmap.put("&#106;","j"); 
		charmap.put("&#107;","k"); 
		charmap.put("&#108;","l"); 
		charmap.put("&#109;","m"); 
		charmap.put("&#110;","n"); 
		charmap.put("&#111;","o"); 
		charmap.put("&#112;","p"); 
		charmap.put("&#113;","q"); 
		charmap.put("&#114;","r"); 
		charmap.put("&#115;","s"); 
		charmap.put("&#116;","t"); 
		charmap.put("&#117;","u"); 
		charmap.put("&#118;","v"); 
		charmap.put("&#119;","w"); 
		charmap.put("&#120;","x"); 
		charmap.put("&#121;","y"); 
		charmap.put("&#122;","z"); 
		charmap.put("&#123;","{"); 
		charmap.put("&#124;","|"); 
		charmap.put("&#125;","}"); 
		charmap.put("&#126;","~"); 
		charmap.put("&#161;","¡");
		charmap.put("&iexcl;","¡");
		charmap.put("&#162;","¢");
		charmap.put("&cent;","¢");
		charmap.put("&#163;","£");
		charmap.put("&pound;","£");
		charmap.put("&#164;","¤");
		charmap.put("&curren;","¤");
		charmap.put("&#165;","¥");
		charmap.put("&yen;","¥");
		charmap.put("&#166;","¦");
		charmap.put("&brvbar;","¦");
		charmap.put("&#167;","§");
		charmap.put("&sect;","§");
		charmap.put("&#168;","¨");
		charmap.put("&uml;","¨");
		charmap.put("&#169;","©");
		charmap.put("&copy;","©");
		charmap.put("&#170;","ª");
		charmap.put("&ordf;","ª");
		charmap.put("&#171;","«");
		charmap.put("&laquo;","«");
		charmap.put("&#172;","¬");
		charmap.put("&not;","¬");
		charmap.put("&#173;","­");
		charmap.put("&shy;","­");
		charmap.put("&#174;","®");
		charmap.put("&reg;","®");
		charmap.put("&#175;","¯");
		charmap.put("&macr;","¯");
		charmap.put("&#176;","°");
		charmap.put("&deg;","°");
		charmap.put("&#177;","±");
		charmap.put("&plusmn;","±");
		charmap.put("&#178;","²");
		charmap.put("&sup2;","²");
		charmap.put("&#179;","³");
		charmap.put("&sup3;","³");
		charmap.put("&#180;","´");
		charmap.put("&acute;","´");
		charmap.put("&#181;","µ");
		charmap.put("&micro;","µ");
		charmap.put("&#182;","¶");
		charmap.put("&para;","¶");
		charmap.put("&#183;","·");
		charmap.put("&middot;","·");
		charmap.put("&#184;","¸");
		charmap.put("&cedil;","¸");
		charmap.put("&#185;","¹");
		charmap.put("&sup1;","¹");
		charmap.put("&#186;","º");
		charmap.put("&ordm;","º");
		charmap.put("&#187;","»");
		charmap.put("&raquo;","»");
		charmap.put("&#188;","¼");
		charmap.put("&frac14;","¼");
		charmap.put("&#189;","½");
		charmap.put("&frac12;","½");
		charmap.put("&#190;","¾");
		charmap.put("&frac34;","¾");
		charmap.put("&#191;","¿");
		charmap.put("&iquest;","¿");
		charmap.put("&#192;","À");
		charmap.put("&Agrave;","À");
		charmap.put("&#193;","Á");
		charmap.put("&Aacute;","Á");
		charmap.put("&#194;","Â");
		charmap.put("&Acirc;","Â");
		charmap.put("&#195;","Ã");
		charmap.put("&Atilde;","Ã");
		charmap.put("&#196;","Ä");
		charmap.put("&Auml;","Ä");
		charmap.put("&#197;","Å");
		charmap.put("&Aring;","Å");
		charmap.put("&#198;","Æ");
		charmap.put("&AElig;","Æ");
		charmap.put("&#199;","Ç");
		charmap.put("&Ccedil;","Ç");
		charmap.put("&#200;","È");
		charmap.put("&Egrave;","È");
		charmap.put("&#201;","É");
		charmap.put("&Eacute;","É");
		charmap.put("&#202;","Ê");
		charmap.put("&Ecirc;","Ê");
		charmap.put("&#203;","Ë");
		charmap.put("&Euml;","Ë");
		charmap.put("&#204;","Ì");
		charmap.put("&Igrave;","Ì");
		charmap.put("&#205;","Í");
		charmap.put("&Iacute;","Í");
		charmap.put("&#206;","Î");
		charmap.put("&Icirc;","Î");
		charmap.put("&#207;","Ï");
		charmap.put("&Iuml;","Ï");
		charmap.put("&#208;","Ð");
		charmap.put("&ETH;","Ð");
		charmap.put("&#209;","Ñ");
		charmap.put("&Ntilde;","Ñ");
		charmap.put("&#210;","Ò");
		charmap.put("&Ograve;","Ò");
		charmap.put("&#211;","Ó");
		charmap.put("&Oacute;","Ó");
		charmap.put("&#212;","Ô");
		charmap.put("&Ocirc;","Ô");
		charmap.put("&#213;","Õ");
		charmap.put("&Otilde;","Õ");
		charmap.put("&#214;","Ö");
		charmap.put("&Ouml;","Ö");
		charmap.put("&#215;","×");
		charmap.put("&times;","×");
		charmap.put("&#216;","Ø");
		charmap.put("&Oslash;","Ø");
		charmap.put("&#217;","Ù");
		charmap.put("&Ugrave;","Ù");
		charmap.put("&#218;","Ú");
		charmap.put("&Uacute;","Ú");
		charmap.put("&#219;","Û");
		charmap.put("&Ucirc;","Û");
		charmap.put("&#220;","Ü");
		charmap.put("&Uuml;","Ü");
		charmap.put("&#221;","Ý");
		charmap.put("&Yacute;","Ý");
		charmap.put("&#222;","Þ");
		charmap.put("&THORN;","Þ");
		charmap.put("&#223;","ß");
		charmap.put("&szlig;","ß");
		charmap.put("&#224;","à");
		charmap.put("&agrave;","à");
		charmap.put("&#225;","á");
		charmap.put("&aacute;","á");
		charmap.put("&#226;","â");
		charmap.put("&acirc;","â");
		charmap.put("&#227;","ã");
		charmap.put("&atilde;","ã");
		charmap.put("&#228;","ä");
		charmap.put("&auml;","ä");
		charmap.put("&#229;","å");
		charmap.put("&aring;","å");
		charmap.put("&#230;","æ");
		charmap.put("&aelig;","æ");
		charmap.put("&#231;","ç");
		charmap.put("&ccedil;","ç");
		charmap.put("&#232;","è");
		charmap.put("&egrave;","è");
		charmap.put("&#233;","é");
		charmap.put("&eacute;","é");
		charmap.put("&#234;","ê");
		charmap.put("&ecirc;","ê");
		charmap.put("&#235;","ë");
		charmap.put("&euml;","ë");
		charmap.put("&#236;","ì");
		charmap.put("&igrave;","ì");
		charmap.put("&#237;","í");
		charmap.put("&iacute;","í");
		charmap.put("&#238;","î");
		charmap.put("&icirc;","î");
		charmap.put("&#239;","ï");
		charmap.put("&iuml;","ï");
		charmap.put("&#240;","ð");
		charmap.put("&eth;","ð");
		charmap.put("&#241;","ñ");
		charmap.put("&ntilde;","ñ");
		charmap.put("&#242;","ò");
		charmap.put("&ograve;","ò");
		charmap.put("&#243;","ó");
		charmap.put("&oacute;","ó");
		charmap.put("&#244;","ô");
		charmap.put("&ocirc;","ô");
		charmap.put("&#245;","õ");
		charmap.put("&otilde;","õ");
		charmap.put("&#246;","ö");
		charmap.put("&ouml;","ö");
		charmap.put("&#247;","÷");
		charmap.put("&divide;","÷");
		charmap.put("&#248;","ø");
		charmap.put("&oslash;","ø");
		charmap.put("&#249;","ù");
		charmap.put("&ugrave;","ù");
		charmap.put("&#250;","ú");
		charmap.put("&uacute;","ú");
		charmap.put("&#251;","û");
		charmap.put("&ucirc;","û");
		charmap.put("&#252;","ü");
		charmap.put("&uuml;","ü");
		charmap.put("&#253;","ý");
		charmap.put("&yacute;","ý");
		charmap.put("&#254;","þ");
		charmap.put("&thorn;","þ");
		charmap.put("&#255;","ÿ");
		charmap.put("&yuml;","ÿ");
		charmap.put("&#338;","Œ"); 
		charmap.put("&#339;","œ"); 
		charmap.put("&#352;","Š"); 
		charmap.put("&#353;","š"); 
		charmap.put("&#376;","Ÿ"); 
		charmap.put("&#402;","ƒ"); 
		charmap.put("&#8211;","–"); 
		charmap.put("&#8212;","—"); 
		charmap.put("&#8216;","‘"); 
		charmap.put("&#8217;","’"); 
		charmap.put("&#8218;","‚"); 
		charmap.put("&#8220;","“"); 
		charmap.put("&#8221;","”"); 
		charmap.put("&#8222;","„"); 
		charmap.put("&#8224;","†"); 
		charmap.put("&#8225;","‡"); 
		charmap.put("&#8226;","•"); 
		charmap.put("&#8230;","…"); 
		charmap.put("&#8240;","‰"); 
		charmap.put("&#8364;","€");
		charmap.put("&euro;","€");
		charmap.put("&#8482;","™"); 

		// replace all occurrences of all keys to their value
		for (Map.Entry<String, String> entry : charmap.entrySet()) {
		    ssource = ssource.replaceAll(entry.getKey(), entry.getValue());
		}
		
		return(ssource);
		
	}; // UTF8
	
} // class UTF8
